<template>
	<view class="shippingAdress my-mgt-15">
		<view class="adress_box my-mgt-15" v-if="dev.length > 0">
			<view class="adress_box_li my-pdlr-15 my-mgt-15" v-for="(item,index) in dev" :key="item.id">
				<view @click.stop="choseItem(item)">
					<view class="adress_box_li_tlt">
						<text class="name my-mgr-10">{{item.name}}</text>
						<text class="phone">{{item.phone}}</text>
					</view>
					<view class="adress_write">
						<view class="adress_write_left" >
							{{item.province}} {{item.city}} {{item.area}} {{item.address}}
						</view>
						<view class="adress_write_right" @click="updates(item)">
							<image src="https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/lDChHiZdkS_write_icon.png" mode="">
							</image>
						</view>
					</view>
					<view class="change_box">
						<view class="redio_txt">
							<radio style="transform: scale(0.7);" color="#F05329" value="BUSINESS"
								:checked="item.default" v-if="item.default" />
							<image src="https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/WfjyXzxuQl_yangsh_icon.png"
								class="radio_box my-mgr-10" mode="" v-else></image>
							<text>设为默认地址</text>
						</view>
						<view class="del_tlt" @click.stop="delAddress(item.id)">删除</view>
					</view>
				</view>
			</view>
		</view>
		<view style="line-height: 300rpx;text-align: center;" v-else>暂无地址，请添加</view>
		<view style="height: 140rpx;"></view>
		<view class="complete">
			<button class="btn" @click="goaddAddress">+添加新的收货地址</button>
		</view>
	</view>
</template>

<script>
	import {
		getshippingaddressApi,
		deladdressApi
	} from "@/api/myinter.js"
	import {
		createNamespacedHelpers
	} from "vuex";
	const {
		mapActions,
		mapState,
		mapMutations
	} = createNamespacedHelpers(
		"address"
	);
	export default {
		data() {
			return {
				type: 0,
			};
		},
		onLoad(options) {
			this.type = Number(options.type)
			this.getAddressData()
		},
		computed: {
			...mapState(["dev"]),
		},
		methods: {
			...mapActions(["getAddressData"]),
			...mapMutations(["filterData"]),
			// radio切换
			changeRadio(item) {
				this.staffType = item
			},
			goaddAddress() {
				uni.redirectTo({
					url: "/pages/my/addAddress?type=0"
				})
			},
			choseItem(item) {
				// console.log(555,item)
				// debugger;
				//if(this.type===1){
				uni.navigateTo({
					url:'../main/childPages/deviceApply?id='+item.id+'&default='+item.default+'&province='+item.province+'&city='+item.city+'&area='+item.area+'&address='+item.address+'&name='+item.name+'&phone='+item.phone
				})
				//	}
			},
			updates(item) {
				let name = item.name
				let phone = item.phone
				let province = item.province
				let city = item.city
				let area = item.area
				let id = item.id
				let address = item.address
				let ifdefault = item.default
				uni.navigateTo({
					url: `/pages/my/editorAddress?name=${name}&phone=${phone}&province=${province}&city=${city}&area=${area}&id=${id}&address=${address}&ifdefault=${ifdefault}`
				})
			},
			// async getAddress() {
			// 	uni.showLoading({
			// 		title: "正在加载中...."
			// 	})
			// 	const res = await getshippingaddressApi({})
			// 	if (res.statusCode === 200) {
			// 		uni.hideLoading()
			// 		this.dev = res.data.data
			// 	}
			// },
			delAddress(id) {
				let _this = this
				uni.showModal({
					content: '确定要删除该地址吗？',
					cancelColor: '#CCCCCC',
					confirmColor: '#F05329',
					success: (r) => {
						if (r.confirm) {
							_this.del(id)
						} else if (r.cancel) {
							uni.showToast({
								title: "用户取消",
								icon: "none"
							})
						}
					}

				})
			},
			async del(id) {
				let _this = this
				uni.showLoading({
					title: "正在加载中...."
				})
				const res = await deladdressApi(id)
				if (res.statusCode === 200) {
					uni.hideLoading()
					uni.showToast({
						title: "删除成功",
						icon: "success",
						duration: 1000,
						success() {
							_this.getAddressData()
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shippingAdress {
		width: 100%;
		height: 100vh;
		background: #FAFAFA;
		position: relative;

		.adress_box {
			width: 100%;
			height: auto;
			min-height: 267rpx;

			.adress_box_li {
				width: 690rpx;
				height: 267rpx;
				margin: auto;
				background: #FFFFFF;
				border-radius: 20rpx;

				.adress_box_li_tlt {
					width: 100%;
					height: 70rpx;
					line-height: 70rpx;

					.name {
						font-size: 30rpx;
						font-weight: bold;
						color: #333333;
					}

					.phone {
						font-size: 24rpx;
						font-weight: 500;
						color: #CCCCCC;
					}
				}

				.adress_write {
					width: 100%;
					height: 120rpx;
					display: flex;
					align-items: center;
					border-bottom: 1rpx solid #E8E8E8;

					.adress_write_left {
						width: 83%;
						line-height: 40rpx;
						font-size: 24rpx;
						font-weight: 400;
						color: #000000;
					}

					.adress_write_right {
						width: 17%;
						display: flex;
						justify-content: flex-end;

						image {
							width: 30rpx;
							height: 30rpx;
						}
					}
				}

				.change_box {
					width: 100%;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.redio_txt {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						font-weight: 400;
						color: #666666;

						.radio_box {
							width: 40rpx;
							height: 40rpx;
						}
					}

					.del_tlt {
						font-size: 24rpx;
						font-weight: 400;
						color: #666666;
					}
				}
			}
		}

		.complete {
			width: 100%;
			height: 130rpx;
			background: #FFFFFF;
			position: fixed;
			left: 0rpx;
			bottom: 0rpx;

			.btn {
				width: 690rpx;
				line-height: 88rpx;
				margin: 0 auto;
				background: #F05329;
				border-radius: 10rpx;
				font-size: 38rpx;
				font-weight: 500;
				color: #FFFFFF;
			}
		}
	}
</style>
